
package hk.ces.oxfam.patch.obj;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ReutyCheng
 */
public class BeanHelper
{
  private BeanHelper()
  {
  }

  public static <T extends Bean> T pack(Object[] results, BeanPacker<T> packer, Class<T> clazz)
  {
    return packer.pack(results);
  }

  public static <T extends Bean> Object[] release(T bean, BeanReleaser<T> releaser, Class<T> clazz)
  {
    return releaser.release(bean);
  }

  public static <T extends Bean> List<T> pack(List<Object[]> resultsList, BeanPacker<T> packer, Class<T> clazz)
  {
    List<T> list = new ArrayList<T>(resultsList.size());
    for (Object[] results : resultsList)
    {
      list.add(pack(results, packer, clazz));
    }
    return list;
  }

  public static <T extends Bean> List<Object[]> release(List<T> beanResults, BeanReleaser<T> releaser, Class<T> clazz)
  {
    List<Object[]> list = new ArrayList<Object[]>(beanResults.size());
    for (T bean : beanResults)
    {
      list.add(release(bean, releaser, clazz));
    }
    return list;
  }
}
